package com.cjjd.c.feature.subscribe.info;

import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cjjd.c.R;
import com.cjjd.c.ShareKeys;
import com.cjjd.c.base.ActionBarActivity;
import com.cjjd.c.bean.HttpResult;
import com.cjjd.c.bean.subscribe.HotelRoomBaseFacilityBean;
import com.cjjd.c.bean.subscribe.HotelRoomBaseFacilityBean.HotelRoomBaseFacilityeShowModel;
import com.cjjd.c.feature.LoaclImageLoader;
import com.cjjd.c.http.CallbackImpl;
import com.cjjd.c.http.JsonUtils;
import com.cjjd.c.utils.PhoneUtil;
import com.cjjd.c.utils.SharePrefUtil;
import com.youth.banner.Banner;

import java.util.HashMap;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import retrofit2.Call;
import retrofit2.Response;

/**
 * ----------------------------------
 * Created by xyd on 2017/12/18.
 * <p/>
 * 描  述：
 * <p/>
 * 修订历史:
 * ----------------------------------
 */

public class HotelDeviceActivity extends ActionBarActivity {
    @Bind(R.id.banner)
    Banner banner;
    @Bind(R.id.ll_content)
    LinearLayout llContent;

    private String hotelUuid;
    private String roomTypeUuid;

    @Override
    public Object getTitleString() {
        return null;
    }

    @Override
    public int getContentView() {
        return R.layout.activity_hotel_device;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
        getIntentData();
        getData();
    }

    private void getIntentData() {
        hotelUuid = getIntent().getStringExtra("hotelUuid");
        roomTypeUuid = getIntent().getStringExtra("roomTypeUuid");
    }

    private void getData() {

        HashMap<String, Object> h1 = new HashMap<>();
        h1.put("token", SharePrefUtil.getString(mContext, ShareKeys.Token, ""));
        h1.put("sessionId", SharePrefUtil.getString(mContext, ShareKeys.sessionId, ""));
        //h1.put("hotelUuid", hotelUuid);
        h1.put("saleRoomTypeUuid", roomTypeUuid);

        Call<HttpResult<HotelRoomBaseFacilityBean>> call = service.getHotelRoomBaseFacility(JsonUtils.convertParam("getHotelRoomBaseFacility", h1));
        call.enqueue(new CallbackImpl<HotelRoomBaseFacilityBean>() {
            @Override
            public void responseSuccess(Call<HttpResult<HotelRoomBaseFacilityBean>> call, Response<HttpResult<HotelRoomBaseFacilityBean>> response) {
                HotelRoomBaseFacilityBean facilityBean = response.body().getData();
                if (facilityBean != null) {
                    banner.setImageLoader(new LoaclImageLoader())
                            .setImages(facilityBean.picList)
                            .start();

                    for (HotelRoomBaseFacilityeShowModel itemBean : facilityBean.typeList) {

                        LinearLayout linearLayout = new LinearLayout(mContext);
                        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                        linearLayout.setLayoutParams(layoutParams);


                        TextView textViewName = new TextView(mContext);
                        textViewName.setWidth(PhoneUtil.dip2px(90));
                        textViewName.setHeight(PhoneUtil.dip2px(45));
                        textViewName.setText(itemBean.name + ":");
                        linearLayout.addView(textViewName);

                        TextView textViewDesc = new TextView(mContext);
                        textViewDesc.setText(itemBean.desc);
                        linearLayout.addView(textViewDesc);

                        llContent.addView(linearLayout);

                    }
                }
            }
        });

    }

    @OnClick(R.id.btn_next)
    public void onViewClicked() {
        finish();
    }
}
